/**
 * Orienteering Sport Diary Copyright (C) 2009 OSDiary Team
 *
 * This file is part of Orienteering Sport Diary (OSDiary).
 *
 * OSDiary is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see http://www.gnu.org/licenses/.
 */

package org.actions.event;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import java.util.List;
import org.data.Event;
import org.data.ORace;
import org.data.RunRace;
import org.util.DateUtil;
import org.util.EventDAO;

/**
 *
 * @author George Mavchun
 */
public class ShowEventAction extends ActionSupport {
    private Integer eventId;
    private Event event;
    private List<RunRace> runRaces;
    private List<ORace> oRaces;

    @Override
    public String execute() {
        Map session = ActionContext.getContext().getSession();
        Integer userId = (Integer) session.get("id");
        if (null == eventId) {
            eventId = (Integer) session.get("eventId");
        }
        event = EventDAO.getUserEventById(userId, eventId);
//        if (pureEvent != null) {
//            runRaces = EventDAO.getAllRunRacesByEventId(eventId);
//            oRaces = EventDAO.getAllORacesByEventId(eventId);
//            return SUCCESS;
//        }
        return SUCCESS;
    }

    public void setEventId(String eventId) {
        this.eventId = Integer.parseInt(eventId);
    }

    public String getEventId() {
        return eventId.toString();
    }

    public String getName() {
        return event.name;
    }

    public String getPlace() {
        return event.place;
    }

    public String getDateTimeString() {
        return DateUtil.format(event.date.getTime(), DateUtil.DATE_AND_TIME_DISPLAY_FORMAT);
    }

    public List getRunRaces() {
        return runRaces;
    }

    public List getORaces() {
        return oRaces;
    }
}

